package com.example.ims.service;

import com.example.ims.pojo.Customer;
import com.example.ims.repository.CustomerRepository;
import com.example.ims.service.inf.CustomerServiceInf;
import jakarta.transaction.Transactional;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
@Transactional
public class CustomerService implements CustomerServiceInf {
    private final CustomerRepository customerRepository;

    public CustomerService(CustomerRepository customerRepository) {
        this.customerRepository = customerRepository;
    }

    // 添加客户的业务逻辑方法
    public void addCustomer(Customer customer) {
        customerRepository.save(customer);
    }

    // 根据ID查询客户的业务逻辑方法（可用于后续可能的其他业务逻辑，比如更新、删除等操作时查询客户信息）
    public Optional<Customer> findById(Long id) {
        return customerRepository.findById(id);
    }

    // 查询所有客户的业务逻辑方法
    public List<Customer> findAllCustomers() {
        return customerRepository.findAll();
    }

    // 删除客户的业务逻辑方法
    public void deleteCustomerById(Long id) {
        customerRepository.deleteById(id);
    }
}